<?php
	include('header.php');
	$errorNotSet = false;
	$errorWrongMailFormat = false;
	
	if(isset($_POST['form_contact'])){
		if(empty($_POST['surname']))$errorNotSet = true;
		if(empty($_POST['firstname']))$errorNotSet = true;
		if(empty($_POST['mail'])){$errorNotSet = true;}
		else{$errorWrongMailFormat = !Tools::checkMail($_POST['mail']);}
		if(empty($_POST['subject']))$errorNotSet = true;
		if(empty($_POST['message']))$errorNotSet = true;
		
		if(!$errorNotSet && !$errorWrongMailFormat){
			$body = '<html>
			<head>
				<title>Mail de contact</title>
			</head>
			<body>
				<table>
					<tr>
						<td  >Nom</td><td> :</td><td>' . htmlentities($_POST['surname'],ENT_QUOTES) . '</td>
					</tr>
					<tr>
						<td  >Prenom</td><td> :</td><td>' . htmlentities($_POST['firstname'],ENT_QUOTES) . '</td>
					</tr>			
					<tr>
						<td  >Courriel</td><td> :</td><td>' . htmlentities($_POST['mail'],ENT_QUOTES) . '</td>
					</tr>			
					<tr><td  ></td><td></td><td>&nbsp;</td></tr>
					<tr>
						<td  >Sujet</td><td> :</td><td>' . htmlentities($_POST['subject'],ENT_QUOTES) . '</td>
					</tr>	
					<tr><td  ></td><td></td><td>&nbsp;</td></tr>
					<tr>
						<td  >Message</td><td colspan="2">:</td>
					</tr>
				</table>
				<p>' . htmlentities($_POST['message'],ENT_QUOTES) . '</p>
			</body>
			</html>';
		}
	}
	include(TPL_DIR . 'contact.html');
	include('footer.php');
?>